/*
 * TicTacToeGameTableFrameFx.fx
 *
 * Created on Apr 27, 2009, 2:11:33 AM
 */

package com.dg.gaming.tictactoe.client.fx;
import com.dg.gaming.api.common.AbstractConnectionThread;
import com.dg.gaming.api.common.GameModel;
import com.dg.gaming.client.fx.gui.FXMain;
import com.dg.gaming.client.TableConnection;
import com.dg.gaming.tictactoe.client.fx.TicTacToeController;
import com.dg.gaming.tictactoe.common.MsgTicTacToeMove;
import com.dg.gaming.tictactoe.common.TicTacToeModel;
import nanoxml.XMLElement;

/**
 * @author dito
 */

public class TicTacToeGameTableFrameFx extends FXMain {
    var model = new TicTacToeModel();
    var controller:TicTacToeController;
    var boardComponent:TicTacToeBoardComponent ;
    public override function  getGameModel():GameModel {
        return model;
    }
    public override function receiveGameMessage(message:XMLElement) {
        super.receiveGameMessage(message);
         var messageType = message.getName();
        if (messageType.equals(MsgTicTacToeMove.XML_NAME)) {
            var move = new MsgTicTacToeMove(message);
            model.setData(move.getX(), move.getY(), move.getValue());
        }
    }

    public  override  function connectOK(conn:AbstractConnectionThread){
        super.connectOK(conn);
        var c =  conn as TableConnection;
        boardComponent=TicTacToeBoardComponent{model:model};
        controller=TicTacToeController{boardComponent:boardComponent,tmodel:model};
        controller.setModel(model);
        controller.setConnection(c.getTableConn());
        boardComponent.setController(controller);
        gamepanel.setGamePanel(boardComponent);
        setupMVC(model, controller);
    }


}
